package name.nano.server;


import java.util.ArrayList;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import name.nano.client.dto.LocationInTime;
import name.nano.client.dto.PlayerTactic;
import name.nano.client.enums.GameMode;
import name.nano.client.utils.Coordinate;

@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable="true")
public class PlayerTacticDAO {
	@Persistent
	private int playerNum;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    String key;


    @Persistent(serialized="true")
	private Coordinate startLocation;
    
    @Persistent(serialized="true")
	private ArrayList<LocationInTime> moves;
	@Persistent
	private Integer opponentNumber;
	@Persistent
	private GameMode playerMode;
	@Persistent
	String color;
	
	public PlayerTacticDAO(){
		
	}
	public PlayerTacticDAO(int playerNum, Coordinate startLocation,Integer opponent,GameMode playerMode,String color) {
		super();
		this.playerNum = playerNum;
		this.startLocation=startLocation;
		this.opponentNumber=opponent;
		this.playerMode=playerMode;
		this.color=color;
	}
	public PlayerTactic getDTO(){
		PlayerTactic playerTactic = new PlayerTactic(getPlayerNum(),new Coordinate(getStartLocation().x,getStartLocation().y),getOpponentNumber(),getPlayerMode(),getColor());
		ArrayList<LocationInTime> moves2 = getMoves();
		if (moves2!=null)
			playerTactic.setMoves(moves2);
		return playerTactic;
	}
	public PlayerTacticDAO(PlayerTactic playerTactic) {
		this.opponentNumber=playerTactic.getOpponentNumber();
		this.playerNum=playerTactic.getPlayerNum();
		Coordinate startLocation2 = playerTactic.getStartLocation();
		this.startLocation=new Coordinate(startLocation2.getX(),startLocation2.getY());
		this.color=playerTactic.getColor();
	}
	private String getColor() {
		return this.color;
	}
	public ArrayList<LocationInTime> getMoves() {
		return moves;
	}
	
	public void setMoves(ArrayList<LocationInTime> moves) {
		this.moves = moves;
	}
	public int getPlayerNum() {
		return playerNum;
	}
	public void setPlayerNum(int playerNum) {
		this.playerNum = playerNum;
	}
	public Coordinate getStartLocation() {
		return startLocation;
	}
	public void setStartLocation(Coordinate startLocation) {
		this.startLocation = startLocation;
	}
	public Integer getOpponentNumber() {
		return opponentNumber;
	}
	public void setOpponentNumber(Integer opponentNumber) {
		this.opponentNumber = opponentNumber;
	}
	public GameMode getPlayerMode() {
		return playerMode;
	}
	public void setPlayerMode(GameMode playerMode) {
		this.playerMode = playerMode;
	}


}
